const wait = (delay) => {
	return new Promise(function(resolve) {
		setTimeout(resolve, delay)
	})
}


// 吐司提示
const toast = (title, icon = 'none', duration, options) => {
	return uni.showToast({
		title: title || '',
		icon: icon,
		image: (options && options.image) || '',
		duration: duration || 1000,
		mask: (options && options.mask) || true,
	});
}

class Rex {
	static phone = /^1[34578]\d{9}$/;
}

class Navigator {
	static push = (url, params) => {
		return uni.navigateTo({
			url: url + '?' + params,
		});
	};
	static replace = (url, params) => {
		return uni.redirectTo({
			url: url + '?' + params,
		});
	};
	static replaceAll = (url, params) => {
		return uni.reLaunch({
			url: url + '?' + params,
		});
	};
	static switchTab = (url, params) => {
		return uni.switchTab({
			url: url + '?' + params,
		});
	};
	static pop = (pages = 1) => {
		return uni.navigateBack({
			delta: pages,
		});
	};
}



module.exports = {
	wait,
	toast,
	Rex,
	Navigator
}
